﻿@using hc.epm.DataModel.Basic;
@using hc.epm.DataModel.Business;
@using System.Collections.Generic;
@model IEnumerable<Base_Company>
@{
    ViewBag.Title = "选择服务商";
}
<div class="content-right date-wrap fl c">
    <div class="search mt5">
        <form class="layui-form" action="" method="get">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">公司名称 : </label>
                    <div class="layui-input-inline">
                        <input type="text" name="name" id="name" autocomplete="off" class="layui-input" value="@ViewBag.name" maxlength="100" />
                        <input type="hidden" name="selectType" value="@ViewBag.SelectType" />
                    </div>
                </div>
                <input type="submit" class="layui-btn layui-btn-radius layui-btn-warm" lay-filter="search" value="搜 索" />
            </div>
        </form>
    </div>
    <div class="main mt5">
        <div class="layui-form">
            <table class="layui-table" style="text-align:center;word-break:break-all;word-wrap:break-word">
                <thead>
                    <tr>
                        <th width="50" class="table-center">
                            <input type="checkbox" lay-skin="primary" lay-filter="allChoose" />
                        </th>
                        <th class="table-center">序号</th>
                        <th class="table-center">公司名称</th>
                    </tr>
                </thead>
                <tbody>
                    @{
                        int index = 0;
                    }
                    @if (Model != null && Model.Count() > 0)
                    {
                        foreach (var item in Model)
                        {
                            index++;
                            <tr>
                                <td class="table-center">
                                    <input type="checkbox" lay-skin="primary" value="@item.SId" data-name="@item.Name" data-code="@item.Code" />
                                    <input type="hidden" value="@item.SId" data-name="@item.Name" data-code="@item.Code" />
                                </td>
                                <td class="table-center">@index</td>
                                <td>@item.Name</td>
                            </tr>
                        }
                    }
                    else
                    {
                        <tr>
                            <td colspan="2" class="table-center">
                                暂无数据
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
        <div id="page"></div>
    </div>
</div>
<script>
    //若无数据隐藏分页组件
    if ('@ViewBag.Total' == 0) {
        $("#page").hide();
    }
    layui.use(['layer', 'form', 'element', 'laypage'], function () {
        var layer = layui.layer, form = layui.form, element = layui.element, $ = layui.jquery, laypage = layui.laypage;
        //分页
        laypage.render({
            elem: 'page',
            count: '@ViewBag.Total',
            curr: '@ViewBag.pageIndex',
            layout: ['prev', 'page', 'next', 'skip', 'count'],
            jump: function (obj, first) {
                if (!first) {
                    //得到了当前页，用于向服务端请求对应数据
                    var curr = obj.curr;
                    var search = $("form").serialize();
                    window.location.href = "/HcISP/SelectServiceCustomer?pageIndex=" + curr + "&" + search;
                }
            }
        });

        //全选
        form.on('checkbox(allChoose)', function (data) {
            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
            child.each(function (index, item) {
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });
        //关闭弹出层
        $('.cancel').on("click", function () {
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            parent.layer.close(index);//关闭窗口
        });
    });
        function getSelectData() {
            var result = {
                flag: true,
                msg: '',
                data: []
            };
            $('tbody .layui-form-checked').each(function (index) {
                result.data.push({
                    Id: $(this).parent().find("input[type='checkbox']").val() || '',
                    Name: $(this).parent().find("input[type='checkbox']").data('name') || '',
                    Code: $(this).parent().find("input[type='checkbox']").data('code') || ''
                });
            });
            if (result.data.length === 0) {
                result.flag = false;
                result.msg = '请选择服务商公司！';
            }
            return result;
        }
</script>
